package com.smh;

public class Person {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person() {
    }

//    public void keepPet(Dog d,String something){
//        System.out.println("年纪"+age+"岁的"+name+"养了一只"+
//                d.getColour()+"的"+d.getAge()+"的狗");
//        d.eat(something);
//    }
//
//    public void keepPet(Cat c,String something){
//        System.out.println("年纪"+age+"岁的"+name+"养了一只"+
//                c.getColour()+"的"+c.getAge()+"的猫");
//        c.eat(something);
//    }

    public void keepPet(Animal animal,String something){
        if (animal instanceof Dog d){
//            Dog d = (Dog)animal;
            System.out.println("年纪"+age+"岁的"+name+"养了一只"+
                    d.getColour()+"的"+d.getAge()+"的狗");
            d.eat(something);
        }else if(animal instanceof Cat c){
            //Cat c = (Cat)animal;
            System.out.println("年纪"+age+"岁的"+name+"养了一只"+
                    c.getColour()+"的"+c.getAge()+"的猫");
            c.eat(something);
        }

    }
}
